//留言
(function() {
	var db = require("../db/index");
	var config = require("../_include/config");
	var db_table_name = config.dbname.dotnarMessage;
	var db_id_prefix = config.dbIdPrefix.dotnarMessage;
	var helper = require("../_include/helper");
	//构造函数
	var _con = function(info, bus_id, num) {
		var self = this;
		//商品编号
		self._id = db_id_prefix + Math.random().toString(16).substr(2) + (+new Date).toString(16);

		self.info = {};
		self._initInfo(info);

		//回复内容
		self.reply = [];

		//创建时间
		self.createTime = +new Date;

		db.insert(db_table_name, self);
		console.log("生成了一个留言：", info.name, ":", info.title);

	};
	//技能
	module.exports = _con;
	_con.prototype = require("./skill");
	//静态方法
	_con.get = function(Id) {
		var result = db.find_by_id(db_table_name, Id);
		if (result) {
			result.__proto__ = _con.prototype;
		}
		return result;
	}
	//获取全部留言
	_con.getAll = function(num, page) {
		var dotnar_message_list = db.find_all(db_table_name);
		dotnar_message_list = data_cut.page(dotnar_message_list, num, page)
		dotnar_message_list.forEach(function(dotnar_message) {
			dotnar_message.__proto__ = _con.prototype;
		});
		//按时间排序
		return dotnar_message_list.sort(function(message_a, message_b) {
			return message_a.createTime < message_b.createTime;
		});
	}
	var BuffsCon = require("../buff/_con");
	var BusCon = require("../bus/_con");
	var data_cut = require("../_include/data_cut");
}());